<?php
try {
	$dbh = new PDO("sqlite:../data/woodso.com.sqlite", "", "");
	$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
} catch(PDOException $e) {
	echo $e->getMessage();
}

// $result = $db->exec("INSERT INTO content (title) VALUES ('这是一个测试');") or die('error');

$sql = "
	SELECT 
		a.id AS id,
		a.content_id AS content_id,
		b.note AS category_name,
		a.title AS title,
		a.status AS status,
		a.hits AS hits
	FROM 
		content AS a
	LEFT JOIN 
		category AS b
	ON 
		a.category_id = b.id
	;";

$result = $dbh->query($sql);
$rows = $result->fetchAll();

//echo json_encode($rows);
//var_dump($rows);
?>
<!DOCTYPE xHTML>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="keywords" content="woodso.com" />
	<style>
		* {font-family:'Courier New','Monospace','Arial';}
		table,th,td {border-collapse:collapse; border:1px solid gray;}
		th,td {padding:2px 10px;}
	</style>
	<title>良木驭天</title>
</head>
<body>
<h3>良木驭天</h3>
<?php if(empty($rows)): ?>
	<p>Empty</p>
<?php else: ?>
	<table>
		<thead>
			<tr>
				<th>编号</th>
				<th>源自</th>
				<th>分类</th>
				<th>标题</th>
				<th>状态</th>
				<th>点击</th>
			</tr>
		</thead>
		<tbody>
<?php foreach($rows as $v): ?>
			<tr>
				<td><?php echo $v->id ?></td>
				<td><?php echo $v->content_id ?></td>
				<td><?php echo $v->category_name ?></td>
				<td><a href="content/<?php echo $v->id ?>"><?php echo $v->title ?></a></td>
				<td><?php echo $v->status ?></td>
				<td><?php echo $v->hits ?></td>
			</tr>
<?php endforeach ?>
		</tbody>
	</table>
<?php endif ?>
</body>
</html>